#ifndef MODBUSREADINSTRUCTIONLOGIC_H
#define MODBUSREADINSTRUCTIONLOGIC_H

#include <QObject>
#include "instructionEnum.h"
#include "GeneralDefine.h"

class ProgramSet;
class ProgramEngine;
class RegData;
class ModbusReadInstruction;

class ModbusReadInstructionLogic : public QObject
{
    Q_OBJECT
public:

    explicit ModbusReadInstructionLogic(int robotIdIn,
                                        ProgramSet *programSetIn,
                                        ProgramEngine *programEngineIn,
                                        RegData *regDataIn);

    E_PROGRAM_LOOP_RESULT startModbusRead(int programNumIn,const ModbusReadInstruction &instructionIn, int lineIndex);

private:
    int readModbusTcpServer(int portIn, int robotRegisterIndex, int modbusRegisterAddress);//本地为服务器
    int readModbusTcpClient(QString  ipAndPort, int robotRegisterIndex, int modbusRegisterAddress);//远程为服务器
    int readModbusRtuClient(int portIn, int robotRegisterIndex, int modbusRegisterAddress);//远程为服务器


    void addMsg( int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 int parameter1 = 0,
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0,
                 QString message= "");

private:

    ProgramEngine *programEngine;
    ProgramSet *programSet;
    RegData *regData;
    int robotId;
};

#endif // MODBUSREADINSTRUCTIONLOGIC_H
